/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jefoutta
 */
import java.io.*;
import java.util.*;

public class FileManager {

    private static File file = null;
    private static FileReader fr = null;
    private static BufferedReader br = null;
    private FileWriter fw = null;
    private BufferedWriter bw = null;
    private String paths = "/media/jef_stuff/Documents/NetBeansProjects/jefox/file system/";
    private String stemp = null;

    public void open(String fname){
        fname = paths + fname;
        file = new File (fname);
        try{
            fr = new FileReader(file);
            br = new BufferedReader(fr);
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    public ArrayList<String> readAll() throws IOException{
        ArrayList<String> tempList = new ArrayList<String>(0);
        String s = null;

        try{

            while ((s = br.readLine()) != null)
            {
                //if (!(s.contains("\\n")));
                tempList.add(s);
            }

        }catch (FileNotFoundException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
        return tempList;
    }

    public String readLine() throws IOException{
        String s = null;
        try{
            stemp = br.readLine();
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }
        return stemp;
    }

    public void close() throws IOException{
        try{
            fr.close();
            br.close();
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }
    }

    public void createFile(String s) throws IOException{
        try{
            s = paths + s;
            fw = new FileWriter(s);
            bw = new BufferedWriter(fw);
        }catch(Exception e){//Catch exception if any
            e.printStackTrace();
        }
    }

    public void writeLine(String s)throws IOException{
        bw.write(s);
        bw.newLine();
    }

    public void closew()throws IOException{
        bw.close();
    }
}
